---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```
```{r data}
data(instacart)
instacart = instacart %>%
sample_n(1000)
```
Column {data-width=350}
-----------------------------------------------------------------------
### barchart
```{r barchart}
instacart %>%
count(department) %>%
mutate(department = fct_reorder(department, n)) %>%
plot_ly(x = ~department, y = ~n, color = ~department, type = "bar", colors = "viridis")
```
### boxplot
```{r boxplot}
count_product = group_by(instacart, product_name, department) %>%
summarize(sum_order_number = sum(order_number)) %>%
mutate(department = fct_reorder(department, sum_order_number))
count_product %>%
plot_ly(
x = ~department, y = ~sum_order_number, color = ~department , type = "box", colors = "viridis")
```
Column {data-width=650}
-----------------------------------------------------------------------
### scatterplot
```{r scatter}
instacart %>%
filter(department == "produce") %>%
mutate(text_label = str_c("order id: ", order_id)) %>%
plot_ly(
x = ~product_name, y = ~days_since_prior_order, z = ~aisle, type = "scatter3d", mode = "markers",
color = ~aisle, text = ~text_label, alpha = 0.8, colors = "viridis", size = 0.5) %>%
layout(showlegend = TRUE, legend = list(font = list(size = 10)))
```